package subject_set.offer100;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2022/10/15 11:28
 **/
public class Offer30 {
    class MinStack {
        Deque<Integer> stack1;
        Deque<Integer> stack2;

        /** initialize your data structure here. */
        public MinStack() {
            stack1 = new LinkedList<>();
            stack2 = new LinkedList<>();
        }

        public void push(int x) {
            stack1.push(x);
            if(stack2.isEmpty()) stack2.push(x);
            else {
                if(stack2.peek() > x) stack2.push(x);
                else stack2.push(stack2.peek());
            }
        }

        public void pop() {
            stack1.pop();
            stack2.pop();
        }

        public int top() {
            return stack1.peek();
        }

        public int min() {
            return stack2.peek();
        }
    }
}